package com.jiantong.work.impl.dao;

import com.google.common.collect.Maps;
import com.jiantong.work.model.MarkWearManagement;
import io.terminus.common.model.Paging;
import io.terminus.common.mysql.dao.MyBatisDao;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Created by mz03 on 2017/7/20.
 */
@Repository
public class MarkWearManagementDao extends MyBatisDao<MarkWearManagement> {

    /**
     * 根据时间和批号分组,分页查看当前登录人管辖养殖场
     * @param offset
     * @param limit
     * @param criteria
     * @return
     */
    public Paging<MarkWearManagement> pagingOtherPurchaseRecordsFarm(Integer offset, Integer limit, Map<String, Object> criteria) {
        if(criteria == null) {
            criteria = Maps.newHashMap();
        }

        Long total = this.sqlSession.selectOne(this.sqlId("countOtherPurchaseRecordsFarm"), criteria);
        if(total <= 0L) {
            return new Paging(0L, Collections.emptyList());
        } else {
            criteria.put("offset", offset);
            criteria.put("limit", limit);
            List datas = this.sqlSession.selectList(this.sqlId("pagingOtherPurchaseRecordsFarm"), criteria);
            return new Paging(total, datas);
        }
    }



}
